""silent !curl -fLo vim_plug_path  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim


if(has("win32") || has("win95") || has("win64") || has("win16"))
    let g:iswindows=1
else
    let g:iswindows=0
endif
autocmd BufEnter * lcd %:p:h



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"general
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set showcmd

"启动后自动最大化 
if has("win32")
    au GUIEnter * simalt ~x
endif


let g:pydiction_location = 'bundle\pydiction\complete-dict'
let g:pydiction_menu_height = 20

set nocompatible              " be iMproved, required
filetype off                  " required

call plug#begin('~/.vim/bundle/')
" Tell vim-plug we finished declaring plugins, so it can load them
Plug 'VundleVim/Vundle.vim'
Plug  'davidhalter/jedi-vim'
Plug 'scrooloose/syntastic'
Plug 'leshill/vim-json'
Plug 'alfredodeza/jacinto.vim'
Plug 'tpope/vim-fugitive'
Plug 'altercation/vim-colors-solarized'
Plug 'Yggdroot/indentLine'
Plug 'python-rope/ropevim'
Plug 'Bogdanp/pyrepl.vim'
Plug 'mhinz/vim-startify'
Plug 'L9'
Plug 'othree/vim-autocomplpop'
"Plug 'fholgado/minibufexpl.vim'
Plug 'https://github.com/fholgado/minibufexpl.vim.git'
Plug 'vim-scripts/mru.vim'
Plug 'vimwiki/vimwiki'
Plug 'scrooloose/nerdtree'
Plug 'Shougo/neocomplete.vim'
Plug 'Shougo/neosnippet'
Plug 'Shougo/neosnippet-snippets'
" Code commenter
Plug 'scrooloose/nerdcommenter'
" Class/module browser
Plug 'majutsushi/tagbar'
" Code and files fuzzy finder
Plug 'ctrlpvim/ctrlp.vim'
" Extension to ctrlp, for fuzzy command finder
Plug 'fisadev/vim-ctrlp-cmdpalette'
Plug 'tacahiroy/ctrlp-funky'
" Zen coding
Plug 'mattn/emmet-vim'
" Git integration
Plug 'motemen/git-vim'
" Tab list panel
"Plug 'kien/tabman.vim'
" Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Terminal Vim with 256 colors colorscheme
Plug 'fisadev/fisa-vim-colorscheme'
" Consoles as buffers
Plug 'rosenfeld/conque-term'
" Pending tasks list
"Plug 'fisadev/FixedTaskList.vim'
" Surround
Plug 'tpope/vim-surround'
" Autoclose
Plug 'Townk/vim-autoclose'
" Indent text object
"Plug 'michaeljsmith/vim-indent-object'
" Indentation based movements
"Plug 'jeetsukumaran/vim-indentwise'

call plug#end()

filetype plugin indent on    " required

" 设置leader 键 ( vim 默认的leader键为 \)
" 使用 . 或者 , 都影响使用..伤不起
"let mapleader="`"
let mapleader = "\<Space>"
"nmap <Leader><Leader> V

"设置字体
"set guifont=Consolas:h14
"set guifont=Monospace\ 18
"set guifont=Consolas:h12

"非兼容vi模式
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin


"文件有修改的时候自动加载文件
set autoread
"文件的默认编码为utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
"tab 的大小为4个空格字符
set ts=4
"缩进的宽度 >> 
set shiftwidth=4
set tabstop=4
set expandtab
" Be smart when using tabs ;)
set smarttab


"查找的时候自动跳转
set incsearch
set hlsearch " 查找高亮
set ignorecase
"快速保存
nmap <leader>w :w!<cr> 
"快速退出
nmap <leader>q :q!<cr> 
"快速刷新
nmap <leader>e :e<cr> 
"taglist
nmap <leader>l :TlistToggle<cr> 

set splitbelow "窗口的分割会把新窗口放到当前窗口之下
set splitright "窗口的分割会把新窗口放到当前窗口之右

"------------------------------------------
set guioptions-=T           " 隐藏工具栏
set guioptions-=m           " 隐藏菜单栏
set number
syntax on                   " 开启语法高亮
set laststatus=2            " 显示任务栏

"------------------------------------------

set autoindent
set smartindent
set smartcase
"
set formatoptions=q


"设置状态栏的显示
"------------------------------------------
"状态栏依次显示文件名、文件格式、文件类型、光标所在字符的ASCII值、16进制值、所在行、列、文件总行数。
"set statusline=%F%m%r%h%w/ [FORMAT=%{&ff}]/ [TYPE=%Y]/ [ASCII=/%03.3b]/ [HEX=/%02.2B]/ [POS=%04l,%04v][%p%%]/ [LEN=%L]
"set statusline=%F%m%r%h%w/  [TYPE=%Y]/ [ASCII=/%03.3b]/ [HEX=/%02.2B]/ [POS=%04l,%04v][%p%%]/ [LEN=%L]
"
set statusline=
"set statusline +=%1*\ %n\ %*            "buffer number
"set statusline +=%5*%{&ff}%*            "file format
set statusline +=%3*%y%*                "file type

set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''}      "Encoding
set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\            "Encoding2

set statusline +=%4*\ %<%F%*            "full path
set statusline +=%2*%m%*                "modified flag
set statusline +=%1*%=%5l%*             "current line
set statusline +=%2*/%L%*               "total lines
"set statusline+=%0*\ \ %m%r%w\ %P\ \                      "Modified? Readonly? Top/bot.
"set statusline +=%1*%4v\ %*             "virtual column number
"set statusline +=%2*0x%04B\ %*          "character under cursor

hi User0 guifg=#dd6663 guibg=#666666
hi User1 guifg=#eea040 guibg=#666666
hi User3 guifg=#ff66ff guibg=#666666
hi User4 guifg=#a0ee40 guibg=#666666
hi User5 guifg=#eeee40 guibg=#666666
hi User6 guifg=#eeee40 guibg=#666666
"------------------------------------------




" 代码的自动补全
filetype plugin indent on
filetype plugin on


set completeopt=longest,menu
set nobackup " 不自动备份
set noswapfile
set ruler "设置状态栏标尺


"在当前目录查找tags文件
set tags=tags;
"change working directory automatically
set autochdir

"改变选中与未选中的颜色
highlight Pmenu    guibg=darkgrey  guifg=black 
highlight PmenuSel guibg=yellow guifg=black


" automatically reload vimrc when it's saved
au BufWritePost .vimrc so ~/.vimrc
"当改变窗口大小时分屏也自动换
au VimResized * exe "normal! \<c-w>="



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"snipmate 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set runtimepath+=
"set runtimepath+=C:\vim\vim74\bundle\UltiSnips-3.0
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"map 执行快捷键
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F4> :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>


"map <F4> :w<cr>:!python3 %<cr>
nmap <F3> :NERDTreeFind<CR>
map <F8> :e!<CR>
map <F5> :call Do_RunOneFile()<CR>
nmap <A-J> :silent !explorer /select,  "%:p"<CR> 

"nmap <leader>u :silent !TortoiseGitProc.exe /command:pull <CR> 
"nmap <leader>g :silent !TortoiseGitProc.exe /command:commit /path:"%:p:h"<CR> 
"nmap <leader>gg :silent !TortoiseGitProc.exe /command:commit <CR> 
"nmap <leader>t :silent !TortoiseProc.exe /command:commit /path:"%:p:h"<CR> 
nmap <leader>c :!start cmd <cr>
"nmap <leader>r :silent !TortoiseProc.exe /command:commit /path:<c-r>=expand("%:p:h")<cr>
map <C-F12> :!ctags -R  *<CR>  


"replce the black slash
"\ 变/
nmap <C-F1> :s/\\/\//g<CR> 
"/ 变\
nmap <S-F1> :s/\//\\/g<CR> 
"双影 变单影
nmap <C-F2> :s/"/'/g<CR> 
"单影 变双影
nmap <C-F3> :s/'/"/g<CR> 

"for todo list
nmap <M-k> 0i* [ ] <esc>
nmap <M-f> 0f[f rX<esc>
nmap <M-o> i------------------------------------------<CR><CR>------------------------------------------<esc>k0
imap <M-o> <esc>O------------------------------------------<esc>jo------------------------------------------<esc>k0A

"2015-03-23 周一 09:33 上午
"nmap <M-t> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
"imap <M-t> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
nmap <M-t> a<C-R>=strftime("%Y-%m-%d  %H:%M ")<CR><Esc>
imap <M-t> <C-R>=strftime("%Y-%m-%d  %H:%M ")<CR>
"nmap <M-w>:q<cr>


":nmap <C-W>h :!explorer %`dirname %`<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"leader 快捷键
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"fast saving
nmap <leader>w :w!<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"常用操作映射
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" treat long lines as break lines
map j gj
map k gk

"映射fast search
"map <space> /
"c-space 被输入法屏蔽了
map <c-space> ?

nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-h> <C-w>h
nmap <C-l> <C-w>l





"Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
"noremap ` viw
inoremap kj <esc>
map <leader>jj :CtrlPCmdPalette<cr>
map <leader>jk :CtrlPFunky<cr>

imap ;; <Esc>


noremap H ^
noremap L $


"Easy split navigation
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>a  gT
map <leader>s  gt

" Add keyboard shortcuts
map <C-Tab> gt
map <C-S-Tab> gT

" tab navigation mappings
map tn :tabn<CR>
map tp :tabp<CR>
map tm :tabm<CR>
map zz :q<CR>
"map tt :tabnew<CR>

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
"map <leader> pp <esc>i<?php ?><esc>ll<CR> 

" Open vimgrep and put the cursor in the right position
map <leader>gf :vimgrep //g  **/*.*<left><left><left><left><left><left><left><left><left><left>
" Vimgreps in the current file
map <leader>f :vimgrep //g *.*<left><left><left>

" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSelection('gv')<CR>


nmap <C-W>y :let @*=expand("%:p")<CR>

map Q @@


"Insert blank lines without going into insert mode
nmap t o<ESC>k
nmap T O<ESC>j


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"定义的函数
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function Do_RunOneFile()
    " cmd /c 执行指定的命令然后终止
    exec "w"
    if &filetype=="python"
       exec "!start cmd /c python % & pause" 
    elseif &filetype=="lua"
        exec "!start cmd /c lua % & pause"
    elseif &filetype=="shell"
        exec "!start cmd /c sh % & pause"
    elseif &filetype=="dosbatch"
        exec "!start cmd /c % & pause"
    elseif &filetype=="ruby"
        exec "!start cmd /c ruby % & pause"
    elseif &filetype=="php"
        exec "!start cmd /c php % & pause"
    elseif &filetype == 'html'
        exec "!start cmd /c 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' % & pause"
    elseif &filetype == 'javascript'
        exec "!start cmd /c node % & pause"
    elseif &filetype == 'java'
        exec "!start cmd /c java % & pause"
    elseif &filetype == 'gradle'
        exec "!start cmd /c gradle % & pause"
    else
        exec "!start cmd /c % & pause"
    endif

    echo &filetype
endfunction

function! CmdLine(str)
    exe "menu Foo.Bar :" . a:str
    emenu Foo.Bar
    unmenu Foo
endfunction


function! VisualSelection(direction) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", '\\/.*$^~[]')
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'b'
        execute "normal ?" . l:pattern . "^M"
    elseif a:direction == 'gv'
        call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
    elseif a:direction == 'replace'
        call CmdLine("%s" . '/'. l:pattern . '/')
    elseif a:direction == 'f'
        execute "normal /" . l:pattern . "^M"
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"进行Tlist的设置
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"TlistUpdate可以更新tags
map <F11> :silent! Tlist<CR> "
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里，所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边，0的话就是显示在左边
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表，如果想只有1个，设置为1
let Tlist_File_Fold_Auto_Close=1 "非当前文件，函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时，自动推出vim
let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理。不是一直实时更新tags，因为没有必要
let Tlist_Inc_Winwidth=0


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"设置ctags
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()


    let dir = getcwd()
    if filereadable("tags")
        if(g:iswindows==1)
            let tagsdeleted=delete(dir."\\"."tags")
        else
            let tagsdeleted=delete("./"."tags")
        endif
        if(tagsdeleted!=0)
            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
            return
        endif
    endif
    if has("cscope")
        silent! execute "cs kill -1"
    endif
    if filereadable("cscope.files")
        if(g:iswindows==1)
            let csfilesdeleted=delete(dir."\\"."cscope.files")
        else
            let csfilesdeleted=delete("./"."cscope.files")
        endif
        if(csfilesdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
            return
        endif
    endif
    if filereadable("cscope.out")
        if(g:iswindows==1)
            let csoutdeleted=delete(dir."\\"."cscope.out")
        else
            let csoutdeleted=delete("./"."cscope.out")
        endif
        if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
            return
        endif
    endif
    if(executable('ctags'))
        "silent! execute "!ctags -R --c-types=+p --fields=+S *"
        
        if &filetype=="lua"
            echo "what can you see me "
            silent! execute "ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+):(\w+).*$/\2/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*[0-9]+.*$/\1/e/" --regex-MYLU A="/^.*\s*function\s*(\w+)\.(\w+).*$/\2/f/" --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*\{.*$/\1/e/" --regex-MYLUA="/^\s*module\s+ \"(\w+)\".*$/\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.(\w+)\".*$/\1/m,module/" --languages=MYLUA --excmd=number -R ."

        else
            silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
        endif


    endif
    if(executable('cscope') && has("cscope") )
        if(g:iswindows!=1)
            silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
        else
            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
        endif
        silent! execute "!cscope -b"
        execute "normal :"
        if filereadable("cscope.out")
            execut "cs add cscope.out"
        endif
    endif
endfunction


" NERD tree
"let NERDChristmasTree = 1
let NERDTreeIgnore = ['\.o$', '\~$','\.lnk$','\.pyc$','\.swp$','\.png$','\.gif$','\.jpg$','\.ico$', '\.class$', 'pip-log\.txt$', '\.o$', '\.dSYM$']
"let NERDTreeAutoCenter = 0
let NERDTreeShowFiles = 1 " 是否默认显示文件
" let NERDTreeShowHidden = 1 " 是否默认显示隐藏文件
"let NERDTreeWinPos = "right"
"let NERDTreeChDirMode = 2

let g:is_NERDTreeOpen = 0








""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"暂时不用
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设置Gvim的对齐线样式
"let g:indentLine_char = "┊"
"let g:indentLine_first_char = "┊"
" 
"
"let g:indentLine_loaded=1
"map <F9> :IndentLinesToggle<CR>
"let g:indentLine_color_gui='#ffffff'
"let g:indentLine_char = 'c'



"NERDTreeTabsToggle
"let g:nerdtree_tabs_open_on_console_startup=1       "设置打开vim的时候默认打开目录树
"map <leader>n <plug>NERDTreeTabsToggle <CR>         "设置打开目录树的快捷键


"
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction



" vim rc
let g:vimwiki_use_mouse = 1
let g:vimwiki_folding = 1
let g:vimwiki_list = [{'path': 'E:/vimwiki/','path_html': 'E:/vimwiki/html/', 'html_header': 'E:/vimwiki/template/header.tpl',}] 




"------------------------------------------
"关闭文件后仍旧能够撤销
set undofile
"可以撤销的修改次数 short for undolevels
set ul=200
"设置撤销文件目录
set undodir="c:\temp"
set undolevels=1000
set undoreload=10000
"------------------------------------------



"------------------------------------------
"Make File-Open track directory of current 
set browsedir=buffer
"------------------------------------------


"------------------------------------------
"Voom

let g:voom_return_key="<c-t>"
let g:voom_tab_key="<c-p>"

"------------------------------------------




"------------------------------------------
"tab 操作
"在tab 面前加上数字
set guitablabel=%N/\ %t\ %M
map 1 1gt
map 2 2gt
map 3 3gt
map 4 4gt
map 5 5gt
map 6 6gt
map 7 7gt
map 8 8gt
map 9 9gt 
map <M-F1> :Vexplore<cr> & vertical resize 40<cr>
map <M-F2> :tabedit<CR>
map <M-F3> :tabe $MYVIMRC<CR>
noremap <M-`> :q<esc>


"------------------------------------------




"------------------------------------------
"在每次退出一份文件后再重新打开该文件时,希望光标停留在当时退出的地方；也就是说当我程序写到hello.c的第100列时突然有事必须关电脑了,那在我下次打开电脑以vim打开hello.c, 希望光标"还是停留在第100列,怎么办?
"解决方案就是在.vimrc里面加上这一行即可:
"
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif   
"------------------------------------------
"



" 设置vimwiki的标题
"------------------------------------------
hi VimwikiHeader1 guifg=#FF0000
hi VimwikiHeader2 guifg=#EE0000
hi VimwikiHeader3 guifg=#AA0000
hi VimwikiHeader4 guifg=#FF00FF
hi VimwikiHeader5 guifg=#777700
hi VimwikiHeader6 guifg=#bb8800

"------------------------------------------
"

"set not need save the change's before jump to other files
set hidden

"i thought no need to  show this 
"set showmatch


"set list
"set listchars=tab:>.,trail:.,extends:#,nbsp:.
"
"
"

"improve the speed of command input 
nnoremap ; :


" customize the wildmenu
set wildmenu
set wildignore+=*.dll,*.o,*.pyc,*.bak,*.exe,*.jpg,*.jpeg,*.png,*.gif,*$py.class,*.class,*/*.dSYM/*,*.dylib
set wildmode=list:full


" hide matches on <leader>space
nnoremap <leader><space> :nohlsearch<cr>



" tab for brackets
nnoremap <tab> %
vnoremap <tab> %


" Thank you vi
nnoremap Y y$



"对搜索的设置
map ft :call Search_Word()<CR>:copen<CR>
function Search_Word()
let w = expand("<cword>") " 在当前光标位置抓词
execute "vimgrep " . w . " *"
endfunction
function! GetVisual() range
    let reg_save = getreg('"')
    let regtype_save = getregtype('"')
    let cb_save = &clipboard
    set clipboard&
    normal! ""gvy
    let selection = getreg('"')
    call setreg('"', reg_save, regtype_save)
    let &clipboard = cb_save
    return selection
endfunction

vmap <leader>z :%s/<c-r>=GetVisual()<cr>/

let g:startify_bookmarks = [ '~/.vimrc' ]

"Automatically update sessions in two cases:
let g:startify_session_persistence = 1

"命令行的高度
set cmdheight=2




" -----------------------------------------------------------------------------
"  < surround 插件配置 >
" -----------------------------------------------------------------------------
" 快速给单词/句子两边增加符号（包括html标签），缺点是不能用"."来重复命令
" 不过 repeat 插件可以解决这个问题，详细帮助见 :h surround.txt
"
" Old text                  Command     New text ~
" \"Hello *world!"           ds"         Hello world!
" (123+4*56)/2              cs])        (123+456)/2
" \"Look ma, I'm *HTML!"     cs"<q>      <q>Look ma, I'm HTML!</q>
" if *x>3 {                 ysW(        if ( x>3 ) {
"my $str = *whee!;        vllllS'     my $str = 'whee!';


" run file with PHP CLI (CTRL-M)
:autocmd FileType php noremap <C-S-M> :w!<CR>:!D:/soft/xampp/php/php.exe %<CR>

" PHP parser check (CTRL-L)
":autocmd FileType php noremap <C-S-L> :!D:/soft/xampp/php/php.exe -l %<CR>


"au FileType php call AddPHPFuncList()
"function AddPHPFuncList()
    "set dictionary-=d:/qdisk/common/PHP-funclist.txt set dictionary+=d:/qdisk/common/PHP-funclist.txt 
    "set complete-=k complete+=k
"endfunction

"只有在是PHP文件时，才启用PHP补全


"Copy & paste to system clipboard with <Space>p and <Space>y:
vmap <Leader>y "+y
vmap <Leader>d "+d
nmap <Leader>p "+p
nmap <Leader>P "+P
vmap <Leader>p "+p
vmap <Leader>P "+P



"enter  replace g ,and replace black use gg
nnoremap <CR> G
nnoremap <BS> gg




" If you are using a console version of Vim, or dealing
" with a file that changes externally (e.g. a web server log)
" then Vim does not always check to see if the file has been changed.
" The GUI version of Vim will check more often (for example on Focus change),
" and prompt you if you want to reload the file.
"
" There can be cases where you can be working away, and Vim does not
" realize the file has changed. This command will force Vim to check
" more often.
"
" Calling this command sets up autocommands that check to see if the
" current buffer has been modified outside of vim (using checktime)
" and, if it has, reload it for you.
"
" This check is done whenever any of the following events are triggered:
" * BufEnter
" * CursorMoved
" * CursorMovedI
" * CursorHold
" * CursorHoldI
"
" In other words, this check occurs whenever you enter a buffer, move the cursor,
" or just wait without doing anything for 'updatetime' milliseconds.
"
" Normally it will ask you if you want to load the file, even if you haven't made
" any changes in vim. This can get annoying, however, if you frequently need to reload
" the file, so if you would rather have it to reload the buffer *without*
" prompting you, add a bang (!) after the command (WatchForChanges!).
" This will set the autoread option for that buffer in addition to setting up the
" autocommands.
"
" If you want to turn *off* watching for the buffer, just call the command again while
" in the same buffer. Each time you call the command it will toggle between on and off.
"
" WatchForChanges sets autocommands that are triggered while in *any* buffer.
" If you want vim to only check for changes to that buffer while editing the buffer
" that is being watched, use WatchForChangesWhileInThisBuffer instead.
"
command! -bang WatchForChanges                  :call WatchForChanges(@%,  {'toggle': 1, 'autoread': <bang>0})
command! -bang WatchForChangesWhileInThisBuffer :call WatchForChanges(@%,  {'toggle': 1, 'autoread': <bang>0, 'while_in_this_buffer_only': 1})
command! -bang WatchForChangesAllFile           :call WatchForChanges('*', {'toggle': 1, 'autoread': <bang>0})
" WatchForChanges function
"
" This is used by the WatchForChanges* commands, but it can also be
" useful to call this from scripts. For example, if your script executes a
" long-running process, you can have your script run that long-running process
" in the background so that you can continue editing other files, redirects its
" output to a file, and open the file in another buffer that keeps reloading itself
" as more output from the long-running command becomes available.
"
" Arguments:
" * bufname: The name of the buffer/file to watch for changes.
"     Use '*' to watch all files.
" * options (optional): A Dict object with any of the following keys:
"   * autoread: If set to 1, causes autoread option to be turned on for the buffer in
"     addition to setting up the autocommands.
"   * toggle: If set to 1, causes this behavior to toggle between on and off.
"     Mostly useful for mappings and commands. In scripts, you probably want to
"     explicitly enable or disable it.
"   * disable: If set to 1, turns off this behavior (removes the autocommand group).
"   * while_in_this_buffer_only: If set to 0 (default), the events will be triggered no matter which
"     buffer you are editing. (Only the specified buffer will be checked for changes,
"     though, still.) If set to 1, the events will only be triggered while
"     editing the specified buffer.
"   * more_events: If set to 1 (the default), creates autocommands for the events
"     listed above. Set to 0 to not create autocommands for CursorMoved, CursorMovedI,
"     (Presumably, having too much going on for those events could slow things down,
"     since they are triggered so frequently...)
function! WatchForChanges(bufname, ...)
  " Figure out which options are in effect
  if a:bufname == '*'
    let id = 'WatchForChanges'.'AnyBuffer'
    " If you try to do checktime *, you'll get E93: More than one match for * is given
    let bufspec = ''
  else
    if bufnr(a:bufname) == -1
      echoerr "Buffer " . a:bufname . " doesn't exist"
      return
    end
    let id = 'WatchForChanges'.bufnr(a:bufname)
    let bufspec = a:bufname
  end
  if len(a:000) == 0
    let options = {}
  else
    if type(a:1) == type({})
      let options = a:1
    else
      echoerr "Argument must be a Dict"
    end
  end
  let autoread    = has_key(options, 'autoread')    ? options['autoread']    : 0
  let toggle      = has_key(options, 'toggle')      ? options['toggle']      : 0
  let disable     = has_key(options, 'disable')     ? options['disable']     : 0
  let more_events = has_key(options, 'more_events') ? options['more_events'] : 1
  let while_in_this_buffer_only = has_key(options, 'while_in_this_buffer_only') ? options['while_in_this_buffer_only'] : 0
  if while_in_this_buffer_only
    let event_bufspec = a:bufname
  else
    let event_bufspec = '*'
  end
  let reg_saved = @"
  "let autoread_saved = &autoread
  let msg = "\n"
  " Check to see if the autocommand already exists
  redir @"
    silent! exec 'au '.id
  redir END
  let l:defined = (@" !~ 'E216: No such group or event:')
  " If not yet defined...
  if !l:defined
    if l:autoread
      let msg = msg . 'Autoread enabled - '
      if a:bufname == '*'
        set autoread
      else
        setlocal autoread
      end
    end
    silent! exec 'augroup '.id
      if a:bufname != '*'
        "exec "au BufDelete    ".a:bufname . " :silent! au! ".id . " | silent! augroup! ".id
        "exec "au BufDelete    ".a:bufname . " :echomsg 'Removing autocommands for ".id."' | au! ".id . " | augroup! ".id
        exec "au BufDelete    ".a:bufname . " execute 'au! ".id."' | execute 'augroup! ".id."'"
      end
        exec "au BufEnter     ".event_bufspec . " :checktime ".bufspec
        exec "au CursorHold   ".event_bufspec . " :checktime ".bufspec
        exec "au CursorHoldI  ".event_bufspec . " :checktime ".bufspec
      " The following events might slow things down so we provide a way to disable them...
      " vim docs warn:
      "   Careful: Don't do anything that the user does
      "   not expect or that is slow.
      if more_events
        exec "au CursorMoved  ".event_bufspec . " :checktime ".bufspec
        exec "au CursorMovedI ".event_bufspec . " :checktime ".bufspec
      end
    augroup END
    let msg = msg . 'Now watching ' . bufspec . ' for external updates...'
  end
  " If they want to disable it, or it is defined and they want to toggle it,
  if l:disable || (l:toggle && l:defined)
    if l:autoread
      let msg = msg . 'Autoread disabled - '
      if a:bufname == '*'
        set noautoread
      else
        setlocal noautoread
      end
    end
    " Using an autogroup allows us to remove it easily with the following
    " command. If we do not use an autogroup, we cannot remove this
    " single :checktime command
    " augroup! checkforupdates
    silent! exec 'au! '.id
    silent! exec 'augroup! '.id
    let msg = msg . 'No longer watching ' . bufspec . ' for external updates.'
  elseif l:defined
    let msg = msg . 'Already watching ' . bufspec . ' for external updates'
  end
  echo msg
  let @"=reg_saved
endfunction







"copy from 知乎
" Ctrlp 设置{{{
    let g:ctrlp_map = '<c-p>'
    let g:ctrlp_working_path_mode = 'ra'
    set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux 忽略文件
    set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe  " Windows 忽略文件
    let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'

    "nmap <leader>w :w!<cr> 
    
    nmap <leader>b :CtrlPBuffer <cr>
    nmap <leader>t :CtrlPTag <cr>
    nmap <leader>n :CtrlPBufTag <cr>


" }}}







"vim 默认的markdown 格式的插件不支持md 格式的Markdown,所以这里设置md格式的为markdown
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown

let g:vim_markdown_frontmatter=1






   "shell自动增加Header
    function! ShellHeader()      
        call setline(1, '#!/usr/bin/env bash')
        call append(1, '')    
    endfunction    
    autocmd bufnewfile *.sh call ShellHeader() 


        "python文件自动增加Header
    function! InserPyHeader()      
        call setline(1, '#!/usr/bin/env python')    
        call append(1, '# -*- coding: utf-8 -*-')    
        call append(2, '')    
    endfunction    
    autocmd bufnewfile *.py call InserPyHeader() 
    "
    "php文件自动增加Header
    function! PhpHeader()      
        call setline(1, '<?php')    
        call append(1, '')    
    endfunction    
    autocmd bufnewfile *.php call PhpHeader() 




    
"set g:RainbowParenthesesToggle
    
let g:ctags_statusline=1 
let g:ctags_title=1



" Edit the vimrc file
nmap <silent> ,ev :e $MYVIMRC<CR>
nmap <silent> ,sv :so $MYVIMRC<CR>

" Don't redraw while executing macros (good performance config)
set showmatch 
set lazyredraw 


map 0 ^
map 4 $



function! Incr()
  let a = line('.') - line("'<")
  let c = virtcol("'<")
  if a > 0
    execute 'normal! '.c.'|'.a."\<C-a>"
  endif
  normal `<
endfunction
vnoremap <C-a> :call Incr()<CR>








"------------------------------------------
"


"2016-08-18  13:55 unite
"------------------------------------------

let g:unite_source_menu_menus = get(g:,'unite_source_menu_menus',{})
let g:unite_source_menu_menus.git = {
    \ 'description' : '            gestionar repositorios git
        \                            ? [espacio]g',
    \}
let g:unite_source_menu_menus.git.command_candidates = [
    \['? tig                                                        ? ,gt',
        \'normal ,gt'],
    \['? git status       (Fugitive)                                ? ,gs',
        \'Gstatus'],
    \['? git diff         (Fugitive)                                ? ,gd',
        \'Gdiff'],
    \['? git commit       (Fugitive)                                ? ,gc',
        \'Gcommit'],
    \['? git log          (Fugitive)                                ? ,gl',
        \'exe "silent Glog | Unite quickfix"'],
    \['? git blame        (Fugitive)                                ? ,gb',
        \'Gblame'],
    \['? git stage        (Fugitive)                                ? ,gw',
        \'Gwrite'],
    \['? git checkout     (Fugitive)                                ? ,go',
        \'Gread'],
    \['? git rm           (Fugitive)                                ? ,gr',
        \'Gremove'],
    \['? git mv           (Fugitive)                                ? ,gm',
        \'exe "Gmove " input("destino: ")'],
    \['? git push         (Fugitive, salida por buffer)             ? ,gp',
        \'Git! push'],
    \['? git pull         (Fugitive, salida por buffer)             ? ,gP',
        \'Git! pull'],
    \['? git prompt       (Fugitive, salida por buffer)             ? ,gi',
        \'exe "Git! " input("comando git: ")'],
    \['? git cd           (Fugitive)',
        \'Gcd'],
    \]
nnoremap <silent>[menu]g :Unite -silent -start-insert menu:git<CR>



"------------------------------------------





let g:vimwiki_list = [{'path': '~/my_site/','syntax': 'markdown', 'ext': '.wiki'},]
let g:vimwiki_ext2syntax = {'.md': 'markdown',
                  \ '.mkd': 'markdown',
                  \ '.wiki': 'media'}

" 输入 #8输入 enter
iab #8 #coding:utf-8
iab pymain if __name__ == '__main__': 

"MRU
"Mru
nmap <leader>m :MRU<cr> 



" 定义自己的命令
command! -nargs=0 Mypy  call InserPyHeader()
command! -nargs=0 Mytest exec "!start cmd /c py.test % & pause"




"syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"let g:syntastic_python_checkers = ['pylint']
let g:syntastic_python_checkers = ['pyflakes']


"git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim


"if has('gui_running')
  ""set background=light
  "colorscheme default
"else
  "colorscheme Zenburn
"endif



"If you want the selected command to be executed by default, add this to your .vimrc
"有些命令需要参数所以这里就不要马上就执行(自己在ex模式补全)
let g:ctrlp_cmdpalette_execute = 1
let g:ctrlp_funky_matchtype = 'path'



"Note: This option must be set in .vimrc(_vimrc).  NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'

" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell_hist',
    \ 'scheme' : $HOME.'/.gosh_completions'
        \ }

" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'

" Plugin key-mappings.
inoremap <expr><C-g>     neocomplete#undo_completion()
inoremap <expr><C-l>     neocomplete#complete_common_string()

" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
  " For no inserting <CR> key.
  "return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"

" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1

" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB>  pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"

" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags

" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'



" Plugin key-mappings.
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)

" SuperTab like snippets behavior.
"imap <expr><TAB>
" \ pumvisible() ? "\<C-n>" :
" \ neosnippet#expandable_or_jumpable() ?
" \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

" For conceal markers.
if has('conceal')
  set conceallevel=2 concealcursor=niv
endif


